<?php
include_once("adminBase.php");

class Links extends AdminBase{
	private $type = 'links';

	function index()
	{	
		$type = $this->type;
		$sql = "select * from tbl_recom where type='$type' and del_flg='0'";
		$this->db->setQuery($sql);
		$data = $this->db->loadList();
		$this->smarty->assign("rows",$data);
		adminDisplay("admin_links.tpl");
	}
	function save()
	{
		$links = $_POST['link'];
		foreach($links as $key=>$value)
		{
			$temprow = array();
			if(empty($value) && empty($_POST['id'][$key])){
				continue;
			}elseif(empty($value) && !empty($_POST['id'][$key])){
				$temprow['del_flg'] = '1';
				$id = intval($_POST['id'][$key]);
				$this->db->update($temprow,"tbl_recom","where id='".$id."'");
				$this->managerLog($id, 'tbl_recom');
				continue;
			}
			$temprow['type'] = $this->type;
			$temprow['title'] = trim($_POST['title'][$key]);
			$temprow['link'] = trim($_POST['link'][$key]);
			$temprow['recom_id'] = 999;
			if(isset($_POST['id'][$key]) && $_POST['id'][$key] > 0){
				$id = intval($_POST['id'][$key]);
				$this->db->update($temprow,"tbl_recom","where id='".$id."'");
				$this->managerLog($id, 'tbl_recom');
			}else{
				if($id = $this->db->insert($temprow,"tbl_recom")){
					$this->managerLog($id, 'tbl_recom');
				}
			}
		}
		$_SESSION['sysMsg'] = '设置成功';
		$this->index();
	}
}

$link = new Links();